<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Đặng Khánh Trung
 * Date: 11/9/12
 * Time: 6:58 AM
 * To change this template use File | Settings | File Templates.
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla formrule library
jimport('joomla.form.formrule');

/**
 * Form Rule class for the Joomla Framework.
 */
class JFormRuleTencongtrinh extends JFormRule
{
    /**
     * The regular expression.
     *
     * @access      protected
     * @var         string
     * @since       2.5
     */
    protected $regex = '^(\w*)(\s*)(.*){1,128}$';

    public function test(&$element, $value, $group = null, & $input = null, & $form = null)
    {
		// Check for a valid regex.
		if (empty($this->regex))
		{
			throw new JException(JText::sprintf('JLIB_FORM_INVALID_FORM_RULE', get_class($this)));
		}

		// Add unicode property support if available.
		if (JCOMPAT_UNICODE_PROPERTIES)
		{
			$this->modifiers = (strpos($this->modifiers, 'u') !== false) ? $this->modifiers : $this->modifiers . 'u';
		}

		// Test the value against the regular expression.
		if (preg_match(chr(1) . $this->regex . chr(1) . $this->modifiers, $value))
		{
			return true;
		}

        // Build JException object
        $result = new JException(JText::sprintf('COM_VAST_CONGTRINH_TEN_MESSAGE', 1, 128));

		return $result;
    }
}